package Testclass.vueTest;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import Dao.JdbcTools3;
import Model.VueStu;
import com.alibaba.fastjson.JSON;
@WebServlet("/vueStu")
public class VueTestshow extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        resp.setContentType("application/json");
        List<VueStu> vueStus = JdbcTools3.queryBeanList("select * from vuestu", VueStu.class);
        String res = JSON.toJSONString(vueStus);
        System.out.println("后端json格式的字符串 = " + res);
        PrintWriter writer = resp.getWriter();
        writer.write(res);
        writer.flush();
        writer.close();
    }
}
